package com.my.study.anno.driven.conditional;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/11/23 7:55
 **/
@Configuration
public class ConditionConfigure {

    @Bean(name = "bill")
    @Conditional(value = {WindowCondition.class})
    public Person person01() {
        return new Person("bill", 60);
    }

    @Bean(name = "linus")
    @Conditional(value = {LinuxCondition.class})
    public Person person02() {
        return new Person("linus", 50);
    }


    public class Person {
        private String name;
        private Integer age;

        public Person() {
        }

        public Person(String name, Integer age) {
            this.name = name;
            this.age = age;
            System.out.println("init person " + toString());
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
